package com.ynby.newyp.controller;

import com.ynby.newyp.pojo.LoginPojo;
import com.ynby.newyp.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
public class LoginController {
    @Autowired
    LoginService loginService;

    @RequestMapping("/")
    public String loginPage(){
        return "page-login";
    }

    @ResponseBody
    @RequestMapping("login.do")
    public String login(LoginPojo loginPojo, HttpServletRequest request) {
        String info = loginService.login(loginPojo);
       if (info.equals("登录成功")) {
            HttpSession session = request.getSession();
            session.setAttribute("flag","1");
        }
        return info;
    }
}
